﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_reward
	/// </summary>
	public partial class oa_reward
	{
		public oa_reward()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("reward_id", "oa_reward"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int reward_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_reward");
			strSql.Append(" where reward_id=@reward_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reward_id", MySqlDbType.Int32)
};
			parameters[0].Value = reward_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_reward model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_reward(");
			strSql.Append("person_id,reward_date,reward_sort,honor_name,reward_type,reward_content,grant_unit,attach_path,attach_filename,note,reward_grade,reward_other_name)");
			strSql.Append(" values (");
			strSql.Append("@person_id,@reward_date,@reward_sort,@honor_name,@reward_type,@reward_content,@grant_unit,@attach_path,@attach_filename,@note,@reward_grade,@reward_other_name)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@reward_date", MySqlDbType.DateTime),
					new MySqlParameter("@reward_sort", MySqlDbType.Int32,11),
					new MySqlParameter("@honor_name", MySqlDbType.VarChar,128),
					new MySqlParameter("@reward_type", MySqlDbType.Int32,11),
					new MySqlParameter("@reward_content", MySqlDbType.VarChar,256),
					new MySqlParameter("@grant_unit", MySqlDbType.VarChar,256),
					new MySqlParameter("@attach_path", MySqlDbType.VarChar,256),
					new MySqlParameter("@attach_filename", MySqlDbType.VarChar,64),
					new MySqlParameter("@note", MySqlDbType.VarChar,256),
					new MySqlParameter("@reward_grade", MySqlDbType.VarChar,32),
					new MySqlParameter("@reward_other_name", MySqlDbType.VarChar,256)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.reward_date;
			parameters[2].Value = model.reward_sort;
			parameters[3].Value = model.honor_name;
			parameters[4].Value = model.reward_type;
			parameters[5].Value = model.reward_content;
			parameters[6].Value = model.grant_unit;
			parameters[7].Value = model.attach_path;
			parameters[8].Value = model.attach_filename;
			parameters[9].Value = model.note;
			parameters[10].Value = model.reward_grade;
			parameters[11].Value = model.reward_other_name;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_reward model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_reward set ");
			strSql.Append("person_id=@person_id,");
			strSql.Append("reward_date=@reward_date,");
			strSql.Append("reward_sort=@reward_sort,");
			strSql.Append("honor_name=@honor_name,");
			strSql.Append("reward_type=@reward_type,");
			strSql.Append("reward_content=@reward_content,");
			strSql.Append("grant_unit=@grant_unit,");
			strSql.Append("attach_path=@attach_path,");
			strSql.Append("attach_filename=@attach_filename,");
			strSql.Append("note=@note,");
			strSql.Append("reward_grade=@reward_grade,");
			strSql.Append("reward_other_name=@reward_other_name");
			strSql.Append(" where reward_id=@reward_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@reward_date", MySqlDbType.DateTime),
					new MySqlParameter("@reward_sort", MySqlDbType.Int32,11),
					new MySqlParameter("@honor_name", MySqlDbType.VarChar,128),
					new MySqlParameter("@reward_type", MySqlDbType.Int32,11),
					new MySqlParameter("@reward_content", MySqlDbType.VarChar,256),
					new MySqlParameter("@grant_unit", MySqlDbType.VarChar,256),
					new MySqlParameter("@attach_path", MySqlDbType.VarChar,256),
					new MySqlParameter("@attach_filename", MySqlDbType.VarChar,64),
					new MySqlParameter("@note", MySqlDbType.VarChar,256),
					new MySqlParameter("@reward_grade", MySqlDbType.VarChar,32),
					new MySqlParameter("@reward_other_name", MySqlDbType.VarChar,256),
					new MySqlParameter("@reward_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.reward_date;
			parameters[2].Value = model.reward_sort;
			parameters[3].Value = model.honor_name;
			parameters[4].Value = model.reward_type;
			parameters[5].Value = model.reward_content;
			parameters[6].Value = model.grant_unit;
			parameters[7].Value = model.attach_path;
			parameters[8].Value = model.attach_filename;
			parameters[9].Value = model.note;
			parameters[10].Value = model.reward_grade;
			parameters[11].Value = model.reward_other_name;
			parameters[12].Value = model.reward_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int reward_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_reward ");
			strSql.Append(" where reward_id=@reward_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reward_id", MySqlDbType.Int32)
};
			parameters[0].Value = reward_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string reward_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_reward ");
			strSql.Append(" where reward_id in ("+reward_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_reward GetModel(int reward_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select reward_id,person_id,reward_date,reward_sort,honor_name,reward_type,reward_content,grant_unit,attach_path,attach_filename,note,reward_grade,reward_other_name from oa_reward ");
			strSql.Append(" where reward_id=@reward_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reward_id", MySqlDbType.Int32)
};
			parameters[0].Value = reward_id;

			becom.Model.oa_reward model=new becom.Model.oa_reward();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["reward_id"]!=null && ds.Tables[0].Rows[0]["reward_id"].ToString()!="")
				{
					model.reward_id=int.Parse(ds.Tables[0].Rows[0]["reward_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["person_id"]!=null && ds.Tables[0].Rows[0]["person_id"].ToString()!="")
				{
					model.person_id=int.Parse(ds.Tables[0].Rows[0]["person_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["reward_date"]!=null && ds.Tables[0].Rows[0]["reward_date"].ToString()!="")
				{
					model.reward_date=DateTime.Parse(ds.Tables[0].Rows[0]["reward_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["reward_sort"]!=null && ds.Tables[0].Rows[0]["reward_sort"].ToString()!="")
				{
					model.reward_sort=int.Parse(ds.Tables[0].Rows[0]["reward_sort"].ToString());
				}
				if(ds.Tables[0].Rows[0]["honor_name"]!=null && ds.Tables[0].Rows[0]["honor_name"].ToString()!="")
				{
					model.honor_name=ds.Tables[0].Rows[0]["honor_name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["reward_type"]!=null && ds.Tables[0].Rows[0]["reward_type"].ToString()!="")
				{
					model.reward_type=int.Parse(ds.Tables[0].Rows[0]["reward_type"].ToString());
				}
				if(ds.Tables[0].Rows[0]["reward_content"]!=null && ds.Tables[0].Rows[0]["reward_content"].ToString()!="")
				{
					model.reward_content=ds.Tables[0].Rows[0]["reward_content"].ToString();
				}
				if(ds.Tables[0].Rows[0]["grant_unit"]!=null && ds.Tables[0].Rows[0]["grant_unit"].ToString()!="")
				{
					model.grant_unit=ds.Tables[0].Rows[0]["grant_unit"].ToString();
				}
				if(ds.Tables[0].Rows[0]["attach_path"]!=null && ds.Tables[0].Rows[0]["attach_path"].ToString()!="")
				{
					model.attach_path=ds.Tables[0].Rows[0]["attach_path"].ToString();
				}
				if(ds.Tables[0].Rows[0]["attach_filename"]!=null && ds.Tables[0].Rows[0]["attach_filename"].ToString()!="")
				{
					model.attach_filename=ds.Tables[0].Rows[0]["attach_filename"].ToString();
				}
				if(ds.Tables[0].Rows[0]["note"]!=null && ds.Tables[0].Rows[0]["note"].ToString()!="")
				{
					model.note=ds.Tables[0].Rows[0]["note"].ToString();
				}
				if(ds.Tables[0].Rows[0]["reward_grade"]!=null && ds.Tables[0].Rows[0]["reward_grade"].ToString()!="")
				{
					model.reward_grade=ds.Tables[0].Rows[0]["reward_grade"].ToString();
				}
				if(ds.Tables[0].Rows[0]["reward_other_name"]!=null && ds.Tables[0].Rows[0]["reward_other_name"].ToString()!="")
				{
					model.reward_other_name=ds.Tables[0].Rows[0]["reward_other_name"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select reward_id,person_id,reward_date,reward_sort,honor_name,reward_type,reward_content,grant_unit,attach_path,attach_filename,note,reward_grade,reward_other_name ");
			strSql.Append(" FROM oa_reward ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_reward";
			parameters[1].Value = "reward_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

